package net.goutalk.glcs.module.bi.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import net.goutalk.glcs.common.page.ConventPage;
import net.goutalk.glcs.common.page.PageOutput;
import net.goutalk.glcs.common.model.result.R;
import net.goutalk.glcs.common.utils.VoToColumnUtil;
import net.goutalk.glcs.module.bi.dto.AddTable52930Dto;
import net.goutalk.glcs.module.bi.dto.UpdateTable52930Dto;
import cn.dev33.satoken.annotation.SaCheckPermission;
import net.goutalk.glcs.module.bi.dto.Table52930PageDto;
import net.goutalk.glcs.module.bi.entity.Table52930;
import net.goutalk.glcs.module.bi.service.IAaaaService;
import net.goutalk.glcs.module.bi.vo.Table52930PageVo;

import net.goutalk.glcs.module.bi.vo.Table52930Vo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
* @title: aaaa
* @Author 管理员
* @Date: 2023-03-17
* @Version 1.0
*/
@RestController
@RequestMapping("/bi" + "/aaaa")
@Api(value = "/bi"  + "/aaaa",tags = "aaaa代码")
@AllArgsConstructor
public class AaaaController {


    private final IAaaaService aaaaService;

    @GetMapping(value = "/page")
    @ApiOperation(value="Table52930列表(分页)")
    @SaCheckPermission("aaaa:detail")
    public R page(@Valid Table52930PageDto dto){

        LambdaQueryWrapper<Table52930> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper
                .like(StrUtil.isNotBlank(dto.getDanXingWenBen()),Table52930::getDanXingWenBen,dto.getDanXingWenBen())
                .like(StrUtil.isNotBlank(dto.getDuoXingWenBen()),Table52930::getDuoXingWenBen,dto.getDuoXingWenBen())
                .select(Table52930.class,x -> VoToColumnUtil.fieldsToColumns(Table52930PageVo.class).contains(x.getProperty()));
        IPage<Table52930> page = aaaaService.page(ConventPage.getPage(dto), queryWrapper);
        PageOutput<Table52930PageVo> pageOutput = ConventPage.getPageOutput(page, Table52930PageVo.class);
        return R.ok(pageOutput);
    }

    @GetMapping(value = "/info")
    @ApiOperation(value="根据id查询Table52930信息")
    @SaCheckPermission("aaaa:detail")
    public R info(@RequestParam Long id){
        Table52930 table52930 = aaaaService.getById(id);
        if (table52930 == null) {
           return R.error("找不到此数据！");
        }
        return R.ok(BeanUtil.toBean(table52930, Table52930Vo.class));
    }


    @PostMapping
    @ApiOperation(value = "新增Table52930")
    @SaCheckPermission("aaaa:add")
    public R add(@Valid @RequestBody AddTable52930Dto dto){
        Table52930 table52930 = BeanUtil.toBean(dto, Table52930.class);
        return R.ok(aaaaService.save(table52930));

    }

    @PutMapping
    @ApiOperation(value = "修改Table52930")
    @SaCheckPermission("aaaa:edit")
    public R update(@Valid @RequestBody UpdateTable52930Dto dto){

        Table52930 table52930 = BeanUtil.toBean(dto, Table52930.class);
        return R.ok(aaaaService.updateById(table52930));

    }

    @DeleteMapping
    @ApiOperation(value = "删除")
    @SaCheckPermission("aaaa:delete")
    public R delete(@Valid @RequestBody List<Long> ids){
        return R.ok(aaaaService.removeBatchByIds(ids));

    }


}